/*
    Dropdown
    author: zhao xin
    date: 2017.2
*/

! function($) {
    'use strict';

    $.fn.tab = function() {
        this.each(function(index, el) {
            var $el = $(el);
            var $con = $el.siblings('.tab-content');
            var $activeLink = $el.children('.active').children('a');

            if ($activeLink.length && $con.length) {
                $($activeLink.attr('href')).addClass('active');
            }
            
            $el.off().on('click', 'a', function(event) {
                var $link = $(this);
                var $tab = $link.closest('.tab');

                if ($tab.hasClass('disabled')) {
                    return false;
                }

                var href = $link.attr('href');

                if (!$tab.hasClass('active')) {
                    $el.children('.active').removeClass('active');
                    $tab.addClass('active');
                    if (href && href[0] === '#') {
                        $con.children('.active').removeClass('active');
                        $($link.attr('href')).addClass('active');
                        return false;
                    }
                }
            });
        });
    }

    $(document).ready(function() {
        $('.tabs').tab();
    });

}(jQuery);